//
//  DYViewController.m
//  Excellence
//
//  Created by 帝云科技 on 2017/6/16.
//  Copyright © 2017年 diyunkeji. All rights reserved.
//

#import "DYViewController.h"
#import "DYTabBarController.h"

@interface DYViewController ()

@property (nonatomic, assign) BOOL hudBgShow;

@end

@implementation DYViewController

- (void)dealloc {
    NSLog(@"dealloc: %@", NSStringFromClass([self class]));
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    [self dy_initData];
    
    [self dy_initUI];
    
    [self dy_request];
}


- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self NavaigationColor:WhiteColor];
    [self dy_reloadData];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
}

- (void)dy_initData {
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.firstEnterController = YES;
    self.hudBgShow = YES;
}

- (void)dy_initUI{
    
    self.view.backgroundColor = [UIColor whiteColor];
//    self.view.backgroundColor=XHQHexColor(0xFBFBFB);
}

- (void)dy_request{}


- (void)dy_reloadData{}

- (void)dy_HUDBGShow {
    if (self.hudBgShow)
    {
        self.hudBgShow = !self.hudBgShow;
        XHQHUDBGSHOW(self.view);
    }
    else
    {
        XHQHUDSHOW(self.view);
    }
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}

-(void)createLeftBarItem:(NSString *)imageName  titleString:(NSString *)title
{
    UIButton* leftButton=[UIButton buttonWithType:UIButtonTypeCustom];
    leftButton.titleLabel.font=[UIFont systemFontOfSize:16];
    leftButton.frame=CGRectMake(0, 19, 45, 45);
    if (imageName!=nil) {
        [leftButton setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    }
    if (title!=nil) {
        [leftButton setTitle:title forState:UIControlStateNormal];
    }
    [leftButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    leftButton.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
    leftButton.showsTouchWhenHighlighted=YES;
    [leftButton addTarget:self action:@selector(leftButtonClick) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem=[[UIBarButtonItem alloc]initWithCustomView:leftButton];
    self.navigationItem.leftBarButtonItem=leftItem;
}
-(void)leftButtonClick
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)createRightBarItem:(NSString *)imageName  titleString:(NSString *)title
{
    UIButton* rightButton=[UIButton buttonWithType:UIButtonTypeCustom];
    rightButton.frame=CGRectMake(0, 19, 75, 45);
    rightButton.titleLabel.font=kFont(15);
    if (imageName!=nil) {
        [rightButton setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    }
    if (title!=nil) {
        [rightButton setTitle:title forState:UIControlStateNormal];
    }
    [rightButton placeImageTitlePosition:ZYButtonImagePositionRight space:BILIWIDTH(3)];
    [rightButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    rightButton.showsTouchWhenHighlighted=YES;
    rightButton.contentHorizontalAlignment=UIControlContentHorizontalAlignmentRight;
    [rightButton addTarget:self action:@selector(rightClick) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightItem=[[UIBarButtonItem alloc]initWithCustomView:rightButton];
    self.navigationItem.rightBarButtonItem=rightItem;
}
-(void)rightClick
{

}
#pragma mark - getter

- (NSMutableArray *)dataArray {
    if (!_dataArray) {
        _dataArray = [[NSMutableArray alloc]init];
    }
    return _dataArray;
}


-(void)NavaigationColor:(UIColor *)color
{
    
    if ([[UIApplication sharedApplication].keyWindow.rootViewController  isKindOfClass:[DYTabBarController class]]) {
        [self.navigationController.navigationBar setBarTintColor:color];
        if (CGColorEqualToColor(color.CGColor, [UIColor xhq_base].CGColor)) {
            [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor],
                                                                              NSFontAttributeName: [UIFont boldSystemFontOfSize:17]}];
            self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
            self.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];
            
            UIButton *btn=(UIButton *) self.navigationItem.rightBarButtonItem.customView;
            [btn setTitleColor:WhiteColor forState:UIControlStateNormal];
            
            UIButton *leftBtn=(UIButton *) self.navigationItem.leftBarButtonItem.customView;
            [leftBtn setTitleColor:WhiteColor forState:UIControlStateNormal];

            //设置状态栏字体颜色
            [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
            
        }else{
            [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor xhq_aTitle],
                                                                              NSFontAttributeName: [UIFont boldSystemFontOfSize:17]}];
//            [self.navigationController.navigationBar setShadowImage:[Utils imageWithColor:[UIColor colorWithWhite:0 alpha:0.1]]];
//            self.navigationItem.leftBarButtonItem.tintColor = [UIColor xhq_base];
//            self.navigationItem.rightBarButtonItem.tintColor = [UIColor xhq_base];
//            UIButton *btn=(UIButton *) self.navigationItem.rightBarButtonItem.customView;
//            [btn setTitleColor:[UIColor xhq_aTitle] forState:UIControlStateNormal];
//            
//            UIButton *leftBtn=(UIButton *) self.navigationItem.leftBarButtonItem.customView;
//            [leftBtn setTitleColor:[UIColor xhq_aTitle] forState:UIControlStateNormal];
            
            
            [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
            
        }
    }else{
        [self.navigationController.navigationBar setBarTintColor:[UIColor whiteColor]];
        [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
        [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor xhq_aTitle],
                                                                          NSFontAttributeName: [UIFont systemFontOfSize:17]
                                                                          }];
        [self.navigationController.navigationBar setShadowImage:[Utils imageWithColor:[UIColor colorWithWhite:0 alpha:0.1]]];
        
        [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
    }
    
}

@end
